package com.hentie.drawlib;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

import com.hentie.mathlib.Matrix;
import com.hentie.mathlib.Vector2;
import com.hentie.mathlib.Vector3;

public class DrawableObject {
	
	public int getTextureID()
	{
		return glTexture;
	}
	
	public int getVertexCount()
	{
		return 2;
	}
	
	
	public Vector3 position= Vector3.Zero();
	public float rotation = 0;
	public Vector3 scale = Vector3.One();
	public float[] vertexPoints;
	public float[] textureCoords;
	public short[] indicies;
	public Vector3[] normals;
	//public FloatBuffer vertexBuffer;
	//public FloatBuffer textureBuffer;
	//public ShortBuffer indexBuffer;
	public String textureName;
	boolean allocated = false;
/*	public float[] getTextureArray()
	{
		float[] array = new float[textureCoords.length*2];
		for(int i = 0; i < textureCoords.length; i++)
		{
			array[i*2] = textureCoords[i].X();
			array[i*2 + 1] = textureCoords[i].Y();

			
		}
		return array;
	}
*/
	public short[] getIndexArray()
	{
		return indicies;
	}
	
	/*
	
	//Performs transformations
	public float[] getTransformedVertex()
	{
		//Create te
		Matrix trans = Matrix.CreateTranslation(position.X(), position.Y(), position.Z());
		Matrix scaleMatrix = Matrix.CreateScale(scale);
		
		Matrix world = Matrix.Multiply(scaleMatrix,Matrix.Multiply(Matrix.Create2DRotation(rotation), trans));
		return null;//world.Transform(getVertexArray());
		
	}
	*/
	
	/*
	public void AllocateBuffers()
	{
		vertexBuffer = ByteBuffer.allocateDirect(vertexPoints.length*4).order(ByteOrder.nativeOrder()).asFloatBuffer();
		vertexBuffer.rewind();
		indexBuffer = ByteBuffer.allocateDirect(indicies.length*2).order(ByteOrder.nativeOrder()).asShortBuffer();
		indexBuffer.rewind();
		textureBuffer = ByteBuffer.allocateDirect(textureCoords.length*4).order(ByteOrder.nativeOrder()).asFloatBuffer();
		textureBuffer.rewind();
		allocated = true;
		
	}
	
	public void UpdateBuffers()
	{
		

		if(!allocated || vertexBuffer.capacity() < vertexPoints.length*4)
			this.AllocateBuffers();
		
		//Check if they need growing
	

	
		

		
		vertexBuffer.position(0);
		vertexBuffer.put(vertexPoints);
		vertexBuffer.rewind();
		
		textureBuffer.position(0);
		textureBuffer.put(textureCoords);
		textureBuffer.rewind();
		
		indexBuffer.position(0);
		indexBuffer.put(indicies);
		indexBuffer.rewind();
	}
	
	*/
	
	public boolean useTextures;
	public int glTexture = -1;
	
	
	
	

}
